package net.cityside.summer.web.controller;

import java.util.Locale;

import net.cityside.summer.domain.User;
import net.cityside.summer.serivce.IUserService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("user")
public class UserController {

	private static final Logger logger = Logger.getLogger(UserController.class);

	@Autowired
	private IUserService userService;

	@RequestMapping("add")
	public ModelAndView add(@RequestParam String username,
			@RequestParam String password, Locale locale) {
		logger.debug("add() Locale=" + locale);

		User user = new User(username, username, password);
		user = userService.save(user);

		ModelAndView mv = new ModelAndView("home");

		if (user != null) {
			mv.addObject("user", user);
		}
		return mv;
	}
}
